<?php

namespace app\admin\model\sport;

use think\Model;
use app\admin\model\sport\Score;


class SUserDetail extends Model
{

    

    

    // 表名
    protected $name = 'sport_user_detail';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'unit_text'
    ];
    

    
    public function getUnitList()
    {
        return ['ms' => __('Unit ms'), 'meter' => __('Unit meter'), 'sec' => __('Unit sec'), 'an' => __('Unit an')];
    }


    public function getUnitTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['unit']) ? $data['unit'] : '');
        $list = $this->getUnitList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    
    public function item()
    {
        return $this->belongsTo(Score::class, 'sport_score_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

}
